package com.example.xyblog.Common;

import com.example.xyblog.Model.Userinfo;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Configuration
public class LoginIntercepter  implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session= request.getSession(false);
        Userinfo userinfo= (Userinfo) session.getAttribute(ConstantVariable.SESSION_KEY_VALUE);
        System.out.println(userinfo);

        if(userinfo != null){
            //登陆就不管了
            return true;
        }else{
            response.setStatus(401);
            return false;
        }

    }
}
